package com.augurit.gzcgwsp.qyzz.service.impl;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import jxl.Sheet;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.util.HqlUtils;
import com.augurit.common.util.PageUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.excelimportexport.util.ExcelUtil;
import com.augurit.gzcgwsp.excelimportexport.util.FileUtil;
import com.augurit.gzcgwsp.excelimportexport.util.GetFileName;
import com.augurit.gzcgwsp.qyzz.convert.YwRqQyzzInfoConvertor;
import com.augurit.gzcgwsp.qyzz.dao.YwRqQyzzAzWxRyZsDao;
import com.augurit.gzcgwsp.qyzz.dao.YwRqQyzzEquipmentDao;
import com.augurit.gzcgwsp.qyzz.dao.YwRqQyzzInfoDao;
import com.augurit.gzcgwsp.qyzz.entity.YwRqQyzzAzWxRyZs;
import com.augurit.gzcgwsp.qyzz.entity.YwRqQyzzFinalAzWxRyZs;
import com.augurit.gzcgwsp.qyzz.entity.YwRqQyzzFinalJsRy;
import com.augurit.gzcgwsp.qyzz.entity.YwRqQyzzInfo;
import com.augurit.gzcgwsp.qyzz.entity.YwRqQyzzJsRy;
import com.augurit.gzcgwsp.qyzz.entity.YwRqRyzzEquipment;
import com.augurit.gzcgwsp.qyzz.entity.YwRqRyzzFinalEquipment;
import com.augurit.gzcgwsp.qyzz.entity.YwRqRyzzFinalOtherEvidence;
import com.augurit.gzcgwsp.qyzz.entity.YwRqRyzzOtherEvidence;
import com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService;
import com.augurit.gzcgwsp.qyzz.web.form.YwRqQyzzInfoForm;
import com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService;
import com.augurit.gzcgwsp.sendNotice.service.IYwMtbjlshInfoService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceForWbService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.gzcgwsp.ssgd.entity.YwRqSsgdSqb;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.ywcmn.entity.YwComFinalQyxx;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxFinalService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjclService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjcllistService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjclForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjcllistForm;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.common.service.impl.WfBusClientServiceImpl;

@Service
@Transactional
public class YwRqQyzzInfoServiceImpl extends WfBusClientServiceImpl<YwRqQyzzInfoForm> implements IYwRqQyzzInfoService {
    private static Logger log = Logger.getLogger(YwRqQyzzInfoServiceImpl.class);
    @Autowired
    private YwRqQyzzInfoDao ywRqQyzzInfoDao;
    @Autowired
    private YwRqQyzzEquipmentDao ywRqQyzzEquipmentDao;
    @Autowired
	private YwRqQyzzAzWxRyZsDao ywRqQyzzAzWxRyZsDao;
    @Autowired
    private IYwComQyxxFinalService ywComQyxxFinalService;
    @Autowired
    private IYwComQyxxService ywComQyxxService;
    @Autowired
    private IYwComSjclService sjclService;
    @Autowired
	private IYwComSjcllistService ywComSjcllistService;
    @Autowired
    private IYwComSjclService ywComSjclService;
    @Autowired
    private IYwMtbjlshInfoService ywMtbjlshInfoService;
    @Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;
    @Autowired
    private IYwWebserviceForWbService ywWebserviceForWbService;
    @Autowired
    private IExchangeStateService exchangeStateService;
    @Autowired
    private IWfServiceEX wfServiceEX;

    /**
     * 根据主键获取Form对象
     */
    @Transactional(readOnly = true)
    public YwRqQyzzInfoForm get(Long id) {
        YwRqQyzzInfo entity = ywRqQyzzInfoDao.get(id);
        YwRqQyzzInfoForm form = YwRqQyzzInfoConvertor.convertVoToForm(entity);
        YwComQyxxForm qyxxform = ywComQyxxService.get(form.getQyid());
        qyxxform=changeEntity(qyxxform);
        YwRqQyzzInfoConvertor.convertQyxxFormToForm(qyxxform, form);
        YwComSjcllistForm sjclListForm=new YwComSjcllistForm();
		sjclListForm.setAjid(id);
		sjclListForm.setTplcode("rqrsqjazwxqyzz");
        List<YwComSjcllistForm> sjclList = ywComSjcllistService.getList(sjclListForm);
        YwComSjclForm fkForm = new YwComSjclForm();
        fkForm.setFkid(form.getQyid());
        fkForm.setAjid(id);
        fkForm.setTplcode("rqrsqjazwxqyzz");
        List<YwComSjclForm> sjclTpl = ywComSjclService.getList(fkForm);
        for (YwComSjcllistForm listForm : sjclList) {
            boolean hasExists = false;
            for (YwComSjclForm tplForm : sjclTpl) {
                if (tplForm.getTplid() != null && listForm.getId().longValue() == tplForm.getTplid().longValue()) {
                    if (StringUtils.isNotBlank(tplForm.getFilepath())) {
                        listForm.setState("1");
                        listForm.setHasfile("1");
                        listForm.setFilename(tplForm.getFilename());
                        listForm.setFilepath(tplForm.getFilepath());
                        listForm.setFiletype(tplForm.getFiletype());
                    } else {
                        listForm.setState("0");
                        listForm.setHasfile("0");
                    }
                    if (tplForm.getYjs() != null) {
                        listForm.setYjs(Long.valueOf(tplForm.getYjs()));
                    }
                    if (tplForm.getFyjs() != null) {
                        listForm.setFyjs(Long.valueOf(tplForm.getFyjs()));
                    }
                    listForm.setClid(tplForm.getId());
                    if ("1".equals(listForm.getSfdz())) {
                        listForm.setDisabled("1");
                    } else {
                        listForm.setDisabled("0");
                        if (tplForm.getSfdz() == null) {
                            listForm.setSfdz("0");
                        } else {
                            listForm.setSfdz(tplForm.getSfdz());
                        }
                    }
                    hasExists = true;
                }
            }
            if (!hasExists) {
                listForm.setState("0");
                listForm.setHasfile("0");
                if ("1".equals(listForm.getSfdz())) {
                    listForm.setDisabled("1");
                } else {
                    listForm.setDisabled("0");
                }
            }
        }
        form.setSqrq(form.getSqrq2());
        if(sjclList.size()>0)
		{
        	YwComSjcllistForm sjclForm01=sjclList.get(0);
			form.setTitleRow101(sjclForm01.getTitle());
			form.setTitleRow102(sjclForm01.getTitle());
			form.setFyjsRow101(sjclForm01.getFyjs());
			form.setFyjsRow102(sjclForm01.getFyjs());
			form.setFsRow101(sjclForm01.getYjs()+sjclForm01.getFyjs());
			form.setFsRow102(sjclForm01.getYjs()+sjclForm01.getFyjs());
			if("0".equals(sjclForm01.getSfdz()))
			{
				form.setSfdzRow101("");
				form.setSfdzRow102("");
			}else{
				form.setSfdzRow101("√");
				form.setSfdzRow102("√");
			}
			
			YwComSjcllistForm sjclForm02=sjclList.get(1);
			form.setTitleRow201(sjclForm02.getTitle());
			form.setTitleRow202(sjclForm02.getTitle());
			form.setFyjsRow201(sjclForm02.getFyjs());
			form.setFyjsRow202(sjclForm02.getFyjs());
			form.setFsRow201(sjclForm02.getYjs()+sjclForm02.getFyjs());
			form.setFsRow202(sjclForm02.getYjs()+sjclForm02.getFyjs());
			if("0".equals(sjclForm02.getSfdz()))
			{
				form.setSfdzRow201("");
				form.setSfdzRow202("");
			}else{
				form.setSfdzRow201("√");
				form.setSfdzRow202("√");
			}
			
			YwComSjcllistForm sjclForm03=sjclList.get(2);
			form.setTitleRow301(sjclForm03.getTitle());
			form.setTitleRow302(sjclForm03.getTitle());
			form.setFyjsRow301(sjclForm03.getFyjs());
			form.setFyjsRow302(sjclForm03.getFyjs());
			form.setFsRow301(sjclForm03.getYjs()+sjclForm03.getFyjs());
			form.setFsRow302(sjclForm03.getYjs()+sjclForm03.getFyjs());
			if("0".equals(sjclForm03.getSfdz()))
			{
				form.setSfdzRow301("");
				form.setSfdzRow302("");
			}else{
				form.setSfdzRow301("√");
				form.setSfdzRow302("√");
			}
			
			YwComSjcllistForm sjclForm04=sjclList.get(3);
			form.setTitleRow401(sjclForm04.getTitle());
			form.setTitleRow402(sjclForm04.getTitle());
			form.setFyjsRow401(sjclForm04.getFyjs());
			form.setFyjsRow402(sjclForm04.getFyjs());
			form.setFsRow401(sjclForm04.getYjs()+sjclForm04.getFyjs());
			form.setFsRow402(sjclForm04.getYjs()+sjclForm04.getFyjs());
			if("0".equals(sjclForm04.getSfdz()))
			{
				form.setSfdzRow401("");
				form.setSfdzRow402("");
			}else{
				form.setSfdzRow401("√");
				form.setSfdzRow402("√");
			}
			
			
			YwComSjcllistForm sjclForm05=sjclList.get(4);
			form.setTitleRow501(sjclForm05.getTitle());
			form.setTitleRow502(sjclForm05.getTitle());
			form.setFyjsRow501(sjclForm05.getFyjs());
			form.setFyjsRow502(sjclForm05.getFyjs());
			form.setFsRow501(sjclForm05.getYjs()+sjclForm05.getFyjs());
			form.setFsRow502(sjclForm05.getYjs()+sjclForm05.getFyjs());
			if("0".equals(sjclForm05.getSfdz()))
			{
				form.setSfdzRow501("");
				form.setSfdzRow502("");
			}else{
				form.setSfdzRow501("√");
				form.setSfdzRow502("√");
			}
			
			
			YwComSjcllistForm sjclForm06=sjclList.get(5);
			form.setTitleRow601(sjclForm06.getTitle());
			form.setTitleRow602(sjclForm06.getTitle());
			form.setFyjsRow601(sjclForm06.getFyjs());
			form.setFyjsRow602(sjclForm06.getFyjs());
			form.setFsRow601(sjclForm06.getYjs()+sjclForm06.getFyjs());
			form.setFsRow602(sjclForm06.getYjs()+sjclForm06.getFyjs());
			if("0".equals(sjclForm06.getSfdz()))
			{
				form.setSfdzRow601("");
				form.setSfdzRow602("");
			}else{
				form.setSfdzRow601("√");
				form.setSfdzRow602("√");
			}
			
			YwComSjcllistForm sjclForm07=sjclList.get(6);
			form.setTitleRow701(sjclForm07.getTitle());
			form.setTitleRow702(sjclForm07.getTitle());
			form.setFyjsRow701(sjclForm07.getFyjs());
			form.setFyjsRow702(sjclForm07.getFyjs());
			form.setFsRow701(sjclForm07.getYjs()+sjclForm07.getFyjs());
			form.setFsRow702(sjclForm07.getYjs()+sjclForm07.getFyjs());
			if("0".equals(sjclForm07.getSfdz()))
			{
				form.setSfdzRow701("");
				form.setSfdzRow702("");
			}else{
				form.setSfdzRow701("√");
				form.setSfdzRow702("√");
			}
			
			YwComSjcllistForm sjclForm08=sjclList.get(7);
			form.setTitleRow801(sjclForm08.getTitle());
			form.setTitleRow802(sjclForm08.getTitle());
			form.setFyjsRow801(sjclForm08.getFyjs());
			form.setFyjsRow802(sjclForm08.getFyjs());
			form.setFsRow801(sjclForm08.getYjs()+sjclForm08.getFyjs());
			form.setFsRow802(sjclForm08.getYjs()+sjclForm08.getFyjs());
			if("0".equals(sjclForm08.getSfdz()))
			{
				form.setSfdzRow801("");
				form.setSfdzRow802("");
			}else{
				form.setSfdzRow801("√");
				form.setSfdzRow802("√");
			}
			
			YwComSjcllistForm sjclForm09=sjclList.get(8);
			form.setTitleRow901(sjclForm09.getTitle());
			form.setTitleRow902(sjclForm09.getTitle());
			form.setFyjsRow901(sjclForm09.getFyjs());
			form.setFyjsRow902(sjclForm09.getFyjs());
			form.setFsRow901(sjclForm09.getYjs()+sjclForm09.getFyjs());
			form.setFsRow902(sjclForm09.getYjs()+sjclForm09.getFyjs());
			if("0".equals(sjclForm09.getSfdz()))
			{
				form.setSfdzRow901("");
				form.setSfdzRow902("");
			}else{
				form.setSfdzRow901("√");
				form.setSfdzRow902("√");
			}
			
			YwComSjcllistForm sjclForm10=sjclList.get(9);
			form.setTitleRow1001(sjclForm10.getTitle());
			form.setTitleRow1002(sjclForm10.getTitle());
			form.setFyjsRow1001(sjclForm10.getFyjs());
			form.setFyjsRow1002(sjclForm10.getFyjs());
			form.setFsRow1001(sjclForm10.getYjs()+sjclForm10.getFyjs());
			form.setFsRow1002(sjclForm10.getYjs()+sjclForm10.getFyjs());
			if("0".equals(sjclForm10.getSfdz()))
			{
				form.setSfdzRow1001("");
				form.setSfdzRow1002("");
			}else{
				form.setSfdzRow1001("√");
				form.setSfdzRow1002("√");
			}
			
			YwComSjcllistForm sjclForm11=sjclList.get(10);
			form.setTitleRow1101(sjclForm11.getTitle());
			form.setTitleRow1102(sjclForm11.getTitle());
			form.setFyjsRow1101(sjclForm11.getFyjs());
			form.setFyjsRow1102(sjclForm11.getFyjs());
			form.setFsRow1101(sjclForm11.getYjs()+sjclForm11.getFyjs());
			form.setFsRow1102(sjclForm11.getYjs()+sjclForm11.getFyjs());
			if("0".equals(sjclForm11.getSfdz()))
			{
				form.setSfdzRow1101("");
				form.setSfdzRow1102("");
			}else{
				form.setSfdzRow1101("√");
				form.setSfdzRow1102("√");
			}
			
			YwComSjcllistForm sjclForm12=sjclList.get(11);
			form.setTitleRow1201(sjclForm12.getTitle());
			form.setTitleRow1202(sjclForm12.getTitle());
			form.setFyjsRow1201(sjclForm12.getFyjs());
			form.setFyjsRow1202(sjclForm12.getFyjs());
			form.setFsRow1201(sjclForm12.getYjs()+sjclForm12.getFyjs());
			form.setFsRow1202(sjclForm12.getYjs()+sjclForm12.getFyjs());
			if("0".equals(sjclForm12.getSfdz()))
			{
				form.setSfdzRow1201("");
				form.setSfdzRow1202("");
			}else{
				form.setSfdzRow1201("√");
				form.setSfdzRow1202("√");
			}
			
			YwComSjcllistForm sjclForm13=sjclList.get(12);
			form.setTitleRow1301(sjclForm13.getTitle());
			form.setTitleRow1302(sjclForm13.getTitle());
			form.setFyjsRow1301(sjclForm13.getFyjs());
			form.setFyjsRow1302(sjclForm13.getFyjs());
			form.setFsRow1301(sjclForm13.getYjs()+sjclForm13.getFyjs());
			form.setFsRow1302(sjclForm13.getYjs()+sjclForm13.getFyjs());
			if("0".equals(sjclForm13.getSfdz()))
			{
				form.setSfdzRow1301("");
				form.setSfdzRow1302("");
			}else{
				form.setSfdzRow1301("√");
				form.setSfdzRow1302("√");
			}
			
			YwComSjcllistForm sjclForm14=sjclList.get(13);
			form.setTitleRow1401(sjclForm14.getTitle());
			form.setTitleRow1402(sjclForm14.getTitle());
			form.setFyjsRow1401(sjclForm14.getFyjs());
			form.setFyjsRow1402(sjclForm14.getFyjs());
			form.setFsRow1401(sjclForm14.getYjs()+sjclForm14.getFyjs());
			form.setFsRow1402(sjclForm14.getYjs()+sjclForm14.getFyjs());
			if("0".equals(sjclForm14.getSfdz()))
			{
				form.setSfdzRow1401("");
				form.setSfdzRow1402("");
			}else{
				form.setSfdzRow1401("√");
				form.setSfdzRow1402("√");
			}
			
			YwComSjcllistForm sjclForm15=sjclList.get(14);
			form.setTitleRow1501(sjclForm15.getTitle());
			form.setTitleRow1502(sjclForm15.getTitle());
			form.setFyjsRow1501(sjclForm15.getFyjs());
			form.setFyjsRow1502(sjclForm15.getFyjs());
			form.setFsRow1501(sjclForm15.getYjs()+sjclForm15.getFyjs());
			form.setFsRow1502(sjclForm15.getYjs()+sjclForm15.getFyjs());
			if("0".equals(sjclForm15.getSfdz()))
			{
				form.setSfdzRow1501("");
				form.setSfdzRow1502("");
			}else{
				form.setSfdzRow1501("√");
				form.setSfdzRow1502("√");
			}
			
			YwComSjcllistForm sjclForm16=sjclList.get(15);
			form.setTitleRow1601(sjclForm16.getTitle());
			form.setTitleRow1602(sjclForm16.getTitle());
			form.setFyjsRow1601(sjclForm16.getFyjs());
			form.setFyjsRow1602(sjclForm16.getFyjs());
			form.setFsRow1601(sjclForm16.getYjs()+sjclForm16.getFyjs());
			form.setFsRow1602(sjclForm16.getYjs()+sjclForm16.getFyjs());
			if("0".equals(sjclForm16.getSfdz()))
			{
				form.setSfdzRow1601("");
				form.setSfdzRow1602("");
			}else{
				form.setSfdzRow1601("√");
				form.setSfdzRow1602("√");
			}
			
			YwComSjcllistForm sjclForm17=sjclList.get(16);
			form.setTitleRow1701(sjclForm17.getTitle());
			form.setTitleRow1702(sjclForm17.getTitle());
			form.setFyjsRow1701(sjclForm17.getFyjs());
			form.setFyjsRow1702(sjclForm17.getFyjs());
			form.setFsRow1701(sjclForm17.getYjs()+sjclForm17.getFyjs());
			form.setFsRow1702(sjclForm17.getYjs()+sjclForm17.getFyjs());
			if("0".equals(sjclForm17.getSfdz()))
			{
				form.setSfdzRow1701("");
				form.setSfdzRow1702("");
			}else{
				form.setSfdzRow1701("√");
				form.setSfdzRow1702("√");
			}
				
				YwComSjcllistForm sjclForm18=sjclList.get(17);
				form.setTitleRow1801(sjclForm18.getTitle());
				form.setTitleRow1802(sjclForm18.getTitle());
				form.setFyjsRow1801(sjclForm18.getFyjs());
				form.setFyjsRow1802(sjclForm18.getFyjs());
				form.setFsRow1801(sjclForm18.getYjs()+sjclForm18.getFyjs());
				form.setFsRow1802(sjclForm18.getYjs()+sjclForm18.getFyjs());
				if("0".equals(sjclForm18.getSfdz()))
				{
					form.setSfdzRow1801("");
					form.setSfdzRow1802("");
				}else{
					form.setSfdzRow1801("√");
					form.setSfdzRow1802("√");
				}
				
				YwComSjcllistForm sjclForm19=sjclList.get(18);
				form.setTitleRow1901(sjclForm19.getTitle());
				form.setTitleRow1902(sjclForm19.getTitle());
				form.setFyjsRow1901(sjclForm19.getFyjs());
				form.setFyjsRow1902(sjclForm19.getFyjs());
				form.setFsRow1901(sjclForm19.getYjs()+sjclForm19.getFyjs());
				form.setFsRow1902(sjclForm19.getYjs()+sjclForm19.getFyjs());
				if("0".equals(sjclForm19.getSfdz()))
				{
					form.setSfdzRow1901("");
					form.setSfdzRow1902("");
				}else{
					form.setSfdzRow1901("√");
					form.setSfdzRow1902("√");
				}
				
				YwComSjcllistForm sjclForm20=sjclList.get(19);
				form.setTitleRow2001(sjclForm20.getTitle());
				form.setTitleRow2002(sjclForm20.getTitle());
				form.setFyjsRow2001(sjclForm20.getFyjs());
				form.setFyjsRow2002(sjclForm20.getFyjs());
				form.setFsRow2001(sjclForm20.getYjs()+sjclForm20.getFyjs());
				form.setFsRow2002(sjclForm20.getYjs()+sjclForm20.getFyjs());
				if("0".equals(sjclForm20.getSfdz()))
				{
					form.setSfdzRow2001("");
					form.setSfdzRow2002("");
				}else{
					form.setSfdzRow2001("√");
					form.setSfdzRow2002("√");
				}
		}
        form.setLxr2(form.getYwlxr());
        form.setSerialNo2(form.getSerialNo());
        form.setPassword2(form.getPassword());
        return form;
    }
    
    /**
     * 转换几个属性
     * @param qyxxform
     */
    private YwComQyxxForm changeEntity(YwComQyxxForm qyxxform) {
        String dwslGyrq=qyxxform.getDwslGyrq()==null?"":qyxxform.getDwslGyrq();//公福燃气器具
        String dwsJyrq=qyxxform.getDwslJyrq()==null?"":qyxxform.getDwslJyrq();//家用燃气具
        String rsJsry=qyxxform.getRsJsry()==null?"":qyxxform.getRsJsry();//技术人员 
        String rsWxg=qyxxform.getRsWxg()==null?"":qyxxform.getRsWxg();//持证安装维修工
        String rsTotal=qyxxform.getRsTotal()==null?"":qyxxform.getRsTotal();//企业总人数
        if(dwslGyrq.indexOf("（家）")>=0||dwslGyrq.indexOf("(家)")>=0){//含有家就截取
            dwslGyrq=dwslGyrq.substring(0,dwslGyrq.length()-3);
            qyxxform.setDwslGyrq(dwslGyrq);
        }else if(dwslGyrq.indexOf("家")>=0){//含有家就截取
            dwslGyrq=dwslGyrq.substring(0,dwslGyrq.length()-1);
            qyxxform.setDwslGyrq(dwslGyrq);
        }
        if(dwsJyrq.indexOf("（家）")>=0||dwsJyrq.indexOf("(家)")>=0){//含有家就截取
            dwsJyrq=dwsJyrq.substring(0,dwsJyrq.length()-3);
            qyxxform.setDwslJyrq(dwsJyrq);
        }else if(dwsJyrq.indexOf("家")>=0){//含有家就截取
            dwsJyrq=dwsJyrq.substring(0,dwsJyrq.length()-1);
            qyxxform.setDwslJyrq(dwsJyrq);
        }
        if(rsJsry.indexOf("（人）")>=0||rsJsry.indexOf("(人)")>=0){//含有人就截取
            rsJsry=rsJsry.substring(0,rsJsry.length()-3);
            qyxxform.setDwslGyrq(dwslGyrq);
        }else if(rsJsry.indexOf("人")>=0){//含有人就截取
            rsJsry=rsJsry.substring(0,rsJsry.length()-1);
            qyxxform.setRsJsry(rsJsry);
        }
        if(rsWxg.indexOf("（人）")>0||rsWxg.indexOf("(人)")>0){//含有人就截取
            rsWxg=rsWxg.substring(0,rsWxg.length()-3);
            qyxxform.setRsWxg(rsWxg);
        }else if(rsWxg.indexOf("人")>0){//含有人就截取
            rsWxg=rsWxg.substring(0,rsWxg.length()-1);
            qyxxform.setRsWxg(rsWxg);
        }
        if(rsTotal.indexOf("（人）")>0||rsTotal.indexOf("(人)")>0){//含有人就截取
            rsTotal=rsTotal.substring(0,rsTotal.length()-3);
            qyxxform.setRsTotal(rsTotal);
        }else if(rsTotal.indexOf("人")>0){//含有人就截取
            rsTotal=rsTotal.substring(0,rsTotal.length()-1);
            qyxxform.setRsTotal(rsTotal);
        }
        return qyxxform;
        
    }

    public List<YwRqQyzzInfo> getByAcceptNo(String acceptNo) {
    	String sql = "from YwRqQyzzInfo t where t.acceptNo='" + acceptNo + "'";
        List<YwRqQyzzInfo> entityList = ywRqQyzzInfoDao.find(sql);
        return entityList;
    }
    
    public void changeYslState(Long id, Long state,String yslThyy) {
    	StringBuffer sql = new StringBuffer();
    	sql.append("update YwRqQyzzInfo t set t.ysl="+state);
    	if(StringUtils.isNotBlank(yslThyy)){
    		sql.append(" ,t.yslThyy='"+yslThyy+"'");
    	}
    	sql.append(" where t.id="+id);
    	ywRqQyzzInfoDao.getSession().createQuery(sql.toString()).executeUpdate();
    	System.out.println("企业资质收件");
    }
    
    //是否延期办理
    public void changeIsycbl(Long id, String state) {
//        YwRqQyzzInfoForm form = this.get(id);
//        form.setIsycbl(state);
//        this.save(form);
        
        YwRqQyzzInfo entity = ywRqQyzzInfoDao.get(id);
    	entity.setIsycbl(state);
    	ywRqQyzzInfoDao.save(entity);
    }
    //保存结案时间
	public void endSave(Long id) {
//		YwRqQyzzInfoForm form = this.get(id);
//		form.setJarq(new Date());
//		this.save(form);
		
		 YwRqQyzzInfo entity = ywRqQyzzInfoDao.get(id);
		 entity.setJarq(new Date());
		 ywRqQyzzInfoDao.save(entity);
	}
    
    /**
     * 删除Form对象列表
     */
    public void delete(Long... ids) {
        ywRqQyzzInfoDao.delete(ids);
    }

    /**
     * 保存新增或修改的Form对象列表
     */
    public void save(YwRqQyzzInfoForm... forms) {
        if(forms != null)
            for(YwRqQyzzInfoForm form : forms)
                this.save(form);
    }
    
    /**
     * 保存对象
     */
    public void saveEntity(YwRqQyzzInfo ywRqQyzzInfo){
    	ywRqQyzzInfoDao.save(ywRqQyzzInfo);
    }
    
    /**
     * 保存新增或修改的Form对象
     */
    public YwRqQyzzInfo getEntity(Long id){
    	//YwRqQyzzInfo entity = ywRqQyzzInfoDao.get(id);
    	return ywRqQyzzInfoDao.get(id);
    }
    
    /**
     * 保存新增或修改的Form对象
     */
    public void save(YwRqQyzzInfoForm form){
        if (form == null) return;
        
        YwRqQyzzInfo entity = null;
        if(form != null && form.getId() != null){
            entity = ywRqQyzzInfoDao.get(form.getId());
            if (StringUtils.isBlank(entity.getAcceptNo()) || form.getAcceptNo().indexOf("XXXX") > 0) form.setAcceptNo(null);
        }else{
            entity = new YwRqQyzzInfo();
            form.setAcceptNo(null);
        }

        //保存企业信息
        YwComQyxxForm qyxxForm = new YwComQyxxForm();
        if(form.getQyid() == null){
        	if(StringUtils.isNotBlank(form.getSqdw())){
            	YwComQyxxForm ywComQyxxForm = ywComQyxxService.getFormBySqdw(form.getSqdw(), "rqrsqjazwxqyzz");
            	if(ywComQyxxForm != null){
            		qyxxForm = ywComQyxxForm;
            	}
            }
        }
        YwRqQyzzInfoConvertor.convertFormToQyxxForm(form, qyxxForm);
        qyxxForm.setTemplateCode("rqrsqjazwxqyzz");
        ywComQyxxService.update(qyxxForm);        
        form.setQyid(qyxxForm.getId());

        boolean isNewForm = false;
        if (StringUtils.isBlank(form.getAcceptNo())) {
        	//生成政务中心统一查询编号 开始
			Map<String,String> serialNoAndPasswordMap = null;
        	if("Y".equals(form.getSendNotice())){//网办，1
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("1");
        	}else{//大厅，0
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("0");
        	}
        	String serialNo = serialNoAndPasswordMap.get("serialNo");
        	String password = serialNoAndPasswordMap.get("password");
			form.setSerialNo(serialNo);
			form.setPassword(password);
			form.setAcceptNo(serialNo);
    		//生成政务中心统一查询编号 结束
            isNewForm = true;
        }
        
        YwRqQyzzInfoConvertor.convertFormToVo(form, entity);
        ywRqQyzzInfoDao.save(entity);
        form.setId(entity.getId());
        if (isNewForm) {
            sjclService.updateByNewForm(form.getId());
        }
    }

    /**
     * 根据Form对象的查询条件作分页查询
     */
    @Transactional(readOnly = true)
    public Page<YwRqQyzzInfoForm> search(Page<YwRqQyzzInfoForm> page, YwRqQyzzInfoForm form) {
        // 建立新的分页对象
        Page pg = PageUtils.newPageInstance(page);
        // 查询语句及参数
        StringBuffer hql = new StringBuffer("from YwRqInstallentinfo ps where 1=1");
        List values = new ArrayList();
        // 查询条件
        if(form != null){
            
        }
        //排序
        hql.append(HqlUtils.buildOrderBy(page, "ps"));
        
        // 执行分页查询操作
        ywRqQyzzInfoDao.findPage(pg, hql.toString(), values);
        
        // 转换为Form对象列表并赋值到原分页对象中
        List<YwRqQyzzInfoForm> list = YwRqQyzzInfoConvertor.convertVoListToFormList(pg.getResult());
        PageUtils.copy(pg, list, page);
        return page;
    }
    
    /**
     * 根据过滤条件列表作分页查询
     */
    @Transactional(readOnly = true)
    public Page<YwRqQyzzInfoForm> search(Page<YwRqQyzzInfoForm> page, List<PropertyFilter> filters) {
        // 建立新的分页对象
        Page<YwRqQyzzInfo> pg = PageUtils.newPageInstance(page);
        
        // 按过滤条件分页查找对象
        ywRqQyzzInfoDao.findPage(pg, filters);
        
        // 转换为Form对象列表并赋值到原分页对象中
        List<YwRqQyzzInfoForm> list = YwRqQyzzInfoConvertor.convertVoListToFormList(pg.getResult());
        PageUtils.copy(pg, list, page);
        return page;
    }
    
    /**
	 * 通过ID号,改变窗口是否可打印受理通知书状态(1为是；0和空为否)
	 * @param id id号
	 */
	public void changeSendAcceptNotice(Long id){
		YwRqQyzzInfo entity = ywRqQyzzInfoDao.get(id);
		entity.setSendAcceptNotice("1");
		ywRqQyzzInfoDao.save(entity);
	}
	
	/**
	 * 通过ID号,改变窗口是否可打印延期办理结果通知书状态(1为是；0和空为否)
	 * @param id 
	 * @return 
	 */
	public void changeSendYqNotice(Long id){
		YwRqQyzzInfo entity = ywRqQyzzInfoDao.get(id);
		entity.setSendYqNotice("1");
		ywRqQyzzInfoDao.save(entity);
	}
	
	
	/*
     * 安装企业维修资质导入基本信息
     * @see com.augurit.gzcgwsp.excelimportexport.service.IYwRqQyjyxkJbxxbService#importJyxk(jxl.Sheet)
     */
	public String importQyzzInfo(Sheet sheet, String acceptNo, long qyid,
			String username,Map<String,String> params) {
	        String process=params.get("process");
	        String error="";
            String dwmc=ExcelUtil.readData(sheet, 1, 0);//单位名称
            String frdb=ExcelUtil.readData(sheet, 5, 0);//法人代表
            String address=ExcelUtil.readData(sheet, 1, 1);//单位地址
            String post=ExcelUtil.readData(sheet, 5, 1);//邮编
            String email=ExcelUtil.readData(sheet, 1,2);//电子邮箱
            String lxr=ExcelUtil.readData(sheet, 3, 2);//联系人
            String tel=ExcelUtil.readData(sheet, 5, 2);//联系电话
            String gszyhm=ExcelUtil.readData(sheet, 4,3);//工商职业号码
            String zczj=ExcelUtil.readData(sheet, 1, 4);//注册资金
            if(zczj.replace("\\s*", "").indexOf("万元")>0){
            	zczj=zczj.substring(0,zczj.indexOf("万元"));
            }
            String jycsmj=ExcelUtil.readData(sheet, 6, 4);//经营场所面积
            if(StringUtils.isNotBlank(jycsmj)){
            	if(jycsmj.indexOf("m2")>0){
            		jycsmj=jycsmj.substring(0,jycsmj.indexOf("m2")).trim();
            	}
            }
            String jsy=ExcelUtil.readData(sheet, 0, 6);//技术员
            String azwxg=ExcelUtil.readData(sheet, 1, 6);//持证安装维修工
            String qyzs=ExcelUtil.readData(sheet, 4, 6);//企业总人数
            if(qyzs.replace("\\s*", "").indexOf("人")>0){
            	qyzs=qyzs.substring(0,qyzs.indexOf("人"));
            }
            if(jsy.replace("\\s*", "").indexOf("人")>0){
            	jsy=jsy.substring(0,jsy.indexOf("人"));
            }
            if(azwxg.replace("\\s*", "").indexOf("人")>0){
            	azwxg=azwxg.substring(0,azwxg.indexOf("人"));
            }
            String jyrqj=ExcelUtil.readData(sheet, 2, 7);//家用燃气器具
            if(jyrqj.replace("\\s*", "").indexOf("（家）")>0){
            	jyrqj=jyrqj.substring(0,jyrqj.indexOf("（家）"));
            }
            String gfrqj=ExcelUtil.readData(sheet, 2, 8);//公福燃气器具
            if(gfrqj.replace("\\s*", "").indexOf("（家）")>0){
            	gfrqj=gfrqj.substring(0,gfrqj.indexOf("（家）"));
            }
            String qyjj=ExcelUtil.readData(sheet,0, 10);//企业简介
            if("cksa".equals(process)){//如果是窗口收案环节 保存一份原始数据
                YwComFinalQyxx finalQyxx=ywComQyxxFinalService.getEntityByQyId(qyid);
                if(finalQyxx==null){
                    finalQyxx=new YwComFinalQyxx();
                }
                finalQyxx.setQyid(qyid);//设置企业id
                finalQyxx.setGszcdjh(gszyhm);//工商营业执照号码
                //qyxx.setSqdw(dwmc);//单位名称
                finalQyxx.setYwlxrtel(tel);//联系电话
                finalQyxx.setEmail(email);//邮箱
                finalQyxx.setAddress(address);//单位地址
                finalQyxx.setPost(post);//邮编
                finalQyxx.setFddbr(frdb);//法人代表
                finalQyxx.setYwlxr(lxr);//联系人
                finalQyxx.setZczj(zczj);//注册资金
                finalQyxx.setCsmj(jycsmj);//经营面积
                finalQyxx.setRsJsry(jsy);//技术员
                finalQyxx.setRsWxg(azwxg);//持证安装维修工
                finalQyxx.setRsTotal(qyzs);//企业总人数
                finalQyxx.setDwslJyrq(jyrqj);//家用燃气器具
                finalQyxx.setDwslGyrq(gfrqj);//公福燃气器具
                finalQyxx.setQyRemarks(qyjj);//企业简介
                try {
                    ywComQyxxFinalService.saveOrUpdateEntity(finalQyxx);
                } catch (Exception e) {
                    log.error("导入基本信息出现错误，请仔细核对上传资料"+e);
                    error="导入基本信息出现错误，请仔细核对上传资料\n";
                }
            }else{
              try {
                YwComQyxxForm qyxx=ywComQyxxService.get(qyid);
                  if(qyxx!=null){
                	qyxx.setGszcdjh(gszyhm);//工商营业执照号码
                	//qyxx.setSqdw(dwmc);//单位名称
                	qyxx.setYwlxrtel(tel);//联系电话
                	qyxx.setEmail(email);//邮箱
                	qyxx.setAddress(address);//单位地址
                	qyxx.setPost(post);//邮编
                	qyxx.setFddbr(frdb);//法人代表
                	qyxx.setYwlxr(lxr);//联系人
                	qyxx.setZczj(zczj);//注册资金
                	qyxx.setCsmj(jycsmj);//经营面积
                	qyxx.setRsJsry(jsy);//技术员
                	qyxx.setRsWxg(azwxg);//持证安装维修工
                	qyxx.setRsTotal(qyzs);//企业总人数
                	qyxx.setDwslJyrq(jyrqj);//家用燃气器具
                	qyxx.setDwslGyrq(gfrqj);//公福燃气器具
                	qyxx.setQyRemarks(qyjj);//企业简介
                	ywComQyxxService.updateYwComQyxx(qyxx);
                }else{
                	qyxx=new YwComQyxxForm();
                	qyxx.setGszcdjh(gszyhm);//工商营业执照号码
                	//qyxx.setSqdw(dwmc);//单位名称
                	qyxx.setYwlxrtel(tel);//联系电话
                	qyxx.setEmail(email);//邮箱
                	qyxx.setAddress(address);//单位地址
                	qyxx.setPost(post);//邮编
                	qyxx.setFddbr(frdb);//法人代表
                	qyxx.setYwlxr(lxr);//联系人
                	qyxx.setZczj(zczj);//注册资金
                	qyxx.setCsmj(jycsmj);//经营面积
                	qyxx.setRsJsry(jsy);//技术员
                	qyxx.setRsWxg(azwxg);//持证安装维修工
                	qyxx.setRsTotal(qyzs);//企业总人数
                	qyxx.setDwslJyrq(jyrqj);//家用燃气器具
                	qyxx.setDwslGyrq(gfrqj);//公福燃气器具
                	qyxx.setQyRemarks(qyjj);//企业简介
                	ywComQyxxService.save(qyxx);
                  }
            } catch (Exception e) {
                log.error("导入基本信息出现错误，请仔细核对资料"+e);
                error="导入基本信息出现错误，请仔细核对资料\n";
            }
           }
			
			return error;
		}

	     
	
	
	
	
	
	/*
	 * excel 写入基本信息
	 * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#copyWsTwo(jxl.write.WritableSheet, java.lang.String, long)
	 */   
	public void copyWsTwo(WritableSheet wsTwo, String acceptNo, long qyid,String type) {
	    String dwmc="";//单位名称
        String frdb="";//法人代表
        String address="";//单位地址
        String post="";//邮编
        String email="";//邮箱
        String gszyhm="";
        String tel="";//联系电话
        String lxr="";//联系人
        String zczj="";//注册资金
        String jycsmj="";//经营面积
        String jsy="";//技术员
        String azwxg="";//持证安装维修工
        String qyzs="";//企业总人数
        String jyrqj="";//家用燃气器具//家用燃气器具
        String gfrqj="";//公福燃气器具
        String qyjj="";//企业简介
	    if("qyxx".equals(type)){
	        YwComFinalQyxx qyxx=ywComQyxxFinalService.getEntityByQyId(qyid);
	         dwmc=qyxx.getSqdw()==null?"":qyxx.getSqdw();//单位名称
             frdb=qyxx.getFddbr()==null?"":qyxx.getFddbr();//法人代表
             address=qyxx.getAddress()==null?"":qyxx.getAddress();//单位地址
             post=qyxx.getPost()==null?"":qyxx.getPost();//邮编
             email=qyxx.getEmail()==null?"":qyxx.getEmail();//邮箱
             gszyhm=qyxx.getGszcdjh()==null?"":qyxx.getGszcdjh();//工商营业执照号码
             tel=qyxx.getYwlxrtel()==null?"":qyxx.getYwlxrtel();//联系电话
             lxr=qyxx.getYwlxr()==null?"":qyxx.getYwlxr();//联系人
             zczj=qyxx.getZczj()==null?"":qyxx.getZczj();//注册资金
             jycsmj=qyxx.getCsmj()==null?"":qyxx.getCsmj();//经营面积
             jsy=qyxx.getRsJsry()==null?"":qyxx.getRsJsry();//技术员
             azwxg=qyxx.getRsWxg()==null?"":qyxx.getRsWxg();//持证安装维修工
             qyzs=qyxx.getRsTotal()==null?"":qyxx.getRsTotal();//企业总人数
             jyrqj=qyxx.getDwslJyrq()==null?"":qyxx.getDwslJyrq();//家用燃气器具
             gfrqj=qyxx.getDwslGyrq()==null?"":qyxx.getDwslGyrq();//公福燃气器具
             qyjj=qyxx.getQyRemarks()==null?"":qyxx.getQyRemarks();//企业简介
	    }else{
	        YwComQyxxForm qyxx=ywComQyxxService.get(qyid);
	         dwmc=qyxx.getSqdw()==null?"":qyxx.getSqdw();//单位名称
             frdb=qyxx.getFddbr()==null?"":qyxx.getFddbr();//法人代表
             address=qyxx.getAddress()==null?"":qyxx.getAddress();//单位地址
             post=qyxx.getPost()==null?"":qyxx.getPost();//邮编
             email=qyxx.getEmail()==null?"":qyxx.getEmail();//邮箱
             gszyhm=qyxx.getGszcdjh()==null?"":qyxx.getGszcdjh();//工商营业执照号码
             tel=qyxx.getYwlxrtel()==null?"":qyxx.getYwlxrtel();//联系电话
             lxr=qyxx.getYwlxr()==null?"":qyxx.getYwlxr();//联系人
             zczj=qyxx.getZczj()==null?"":qyxx.getZczj();//注册资金
             jycsmj=qyxx.getCsmj()==null?"":qyxx.getCsmj();//经营面积
             jsy=qyxx.getRsJsry()==null?"":qyxx.getRsJsry();//技术员
             azwxg=qyxx.getRsWxg()==null?"":qyxx.getRsWxg();//持证安装维修工
             qyzs=qyxx.getRsTotal()==null?"":qyxx.getRsTotal();//企业总人数
             jyrqj=qyxx.getDwslJyrq()==null?"":qyxx.getDwslJyrq();//家用燃气器具
             gfrqj=qyxx.getDwslGyrq()==null?"":qyxx.getDwslGyrq();//公福燃气器具
             qyjj=qyxx.getQyRemarks()==null?"":qyxx.getQyRemarks();//企业简介
	    }
		try {
	 			zczj=zczj.indexOf("万元")>0?zczj:zczj+"万元";
	 			jycsmj=jycsmj.indexOf("m2")>0?jycsmj:jycsmj+"m2";
	 			jsy=jsy.indexOf("人")>0?jsy:jsy+"人";
	 			azwxg=azwxg.indexOf("人")>0?azwxg:azwxg+"人";
	 			qyzs=qyzs.indexOf("人")>0?qyzs:qyzs+"人";
	 			jyrqj=jyrqj.indexOf("（家）")>0?jyrqj:jyrqj+"（家）";
	 			gfrqj=gfrqj.indexOf("（家）")>0?gfrqj:gfrqj+"（家）";
	 			
	 			WritableCellFormat wcf = new WritableCellFormat();
	 			wcf.setBorder(Border.ALL, BorderLineStyle.THIN);
	 			wcf.setAlignment(Alignment.CENTRE);
	 			wcf.setVerticalAlignment(VerticalAlignment.CENTRE); 
	 			WritableCellFormat wcf1 = new WritableCellFormat();
	 			wcf1.setBorder(Border.ALL, BorderLineStyle.THIN);
	 			wcf1.setAlignment(Alignment.LEFT);
	 			wcf1.setVerticalAlignment(VerticalAlignment.TOP); 
				ExcelUtil.modiStrCell2(wsTwo, 1, 0, dwmc, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 5, 0, frdb, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 1, 1, address, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 5, 1, post, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 1, 2, email, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 3, 2, lxr, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 5, 2, tel, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 5, 2, tel, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 4, 3, gszyhm, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 1, 4, zczj, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 6, 4, jycsmj, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 0, 6, jsy, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 1, 6, azwxg, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 4, 6, qyzs, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 2, 7, jyrqj, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 2, 8, gfrqj, wcf);
				ExcelUtil.modiStrCell2(wsTwo, 0, 10, qyjj, wcf1);
			
		}catch (Exception e) {
			log.error("受理编号"+acceptNo+"写入基本信息错误"+e);
		}
		
	}


	/*
	 * 写入名称(non-Javadoc)
	 * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#copyWsOne(jxl.write.WritableSheet, java.lang.String, long)
	 */
	public void copyWsOne(WritableSheet ws, String acceptNo, long qyid) {
		YwComQyxxForm qyxx=ywComQyxxService.get(qyid);
		
		 YwRqQyzzInfo info = ywRqQyzzInfoDao.getInfoByQyid(qyid,acceptNo);
		try {	   
			WritableFont font = new WritableFont(WritableFont.createFont("宋体"),14);
			WritableCellFormat wcf = new WritableCellFormat(font);
			wcf.setBorder(Border.ALL, BorderLineStyle.THIN);
			wcf.setAlignment(Alignment.LEFT);
			if(qyxx!=null){
				String dwmc=qyxx.getSqdw()==null?"":qyxx.getSqdw();//单位名称
				Date ieiDate =info.getIeiDate();
				 String date=DateUtilsEX.dateFormate(ieiDate, "yyyy年MM月dd日");
				 		dwmc="                 申请单位："+dwmc;
				 String sqrq="                 申请日期："+date;
				ExcelUtil.modiStrCell2(ws, 0, 9, dwmc, wcf);
				ExcelUtil.modiStrCell2(ws, 0, 12, sqrq, wcf);
			}
		}catch (Exception e) {
				log.error("受理编号"+acceptNo+"写入第一个工作表错误"+e);
		}
	}

	/*
	 * 获取设备
	 * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#getEquipment(java.lang.Long)
	 */
	public YwRqRyzzEquipment getEquipment(Long eid) {
		
		return ywRqQyzzEquipmentDao.getEntity(eid);
	}

	/*
	 * 删除设备
	 * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#delEquipment(java.lang.Long)
	 */
	public void delEquipment(Long eid) {
		YwRqRyzzEquipment entity=ywRqQyzzEquipmentDao.getEntity(eid);
		ywRqQyzzEquipmentDao.delete(entity);
	}

	/*
	 * 生成证书编号
	 * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#createZsbh(com.augurit.gzcgwsp.qyzz.web.form.YwRqQyzzInfoForm)
	 */
    public void createZsbh(YwRqQyzzInfoForm form) {
      String num=this.buildZsbh(form);
      //form.setZsbh(num);
        
    }
    
    /**
     * 生成的证书编号
     * @return
     */
    private String buildZsbh(YwRqQyzzInfoForm form){
        Long qyid=form.getQyid();
        YwComQyxxForm qyxxForm=ywComQyxxService.get(qyid);
        qyxxForm.getQylx();
        return "";
    }
    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#getYwComFinalQyxx(java.lang.String)
     */
    public YwComFinalQyxx getYwComFinalQyxx(Long qyid) {
        YwComFinalQyxx finalQyxx=ywComQyxxFinalService.getEntityByQyId(qyid);
        return finalQyxx;
    }


    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#getFinalJsRys(java.lang.Long)
     */
    public List<YwRqQyzzFinalJsRy> getFinalJsRys(Long qyid) {
      String sql=" from " +YwRqQyzzFinalJsRy.class.getName()+" where qyid='"+qyid+"'";
      return this.ywRqQyzzInfoDao.find(sql);
    }

    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#getJsRys(java.lang.Long, java.lang.String)
     */
    public List<YwRqQyzzJsRy> getJsRys(Long qyid, String acceptNo) {
        String sql=" from " +YwRqQyzzJsRy.class.getName()+" where qyid='"+qyid+"' and acceptNo='"+acceptNo+"'";
        return ywRqQyzzInfoDao.find(sql);
    }

    public List<YwRqQyzzAzWxRyZs> getAzWxRys(Long qyid, String acceptNo) {
        String sql=" from " +YwRqQyzzAzWxRyZs.class.getName()+" where qyid='"+qyid+"' and acceptNo='"+acceptNo+"'";
        return ywRqQyzzInfoDao.find(sql);
    }

    public List<YwRqQyzzFinalAzWxRyZs> getFinalAzWxRys(Long qyid) {
        String sql=" from " +YwRqQyzzFinalAzWxRyZs.class.getName()+" where qyid='"+qyid+"'";
        return ywRqQyzzInfoDao.find(sql);
    }

    public List<YwRqRyzzEquipment> getEquipments(Long qyid,String acceptNo) {
        String sql=" from " +YwRqRyzzEquipment.class.getName()+" where qyid='"+qyid+"' and acceptNo='"+acceptNo+"'";
        return ywRqQyzzInfoDao.find(sql);
    }

    public List<YwRqRyzzFinalEquipment> getFinalEquipments(Long qyid) {
        String sql=" from " +YwRqRyzzFinalEquipment.class.getName()+" where qyid='"+qyid+"'";
        return ywRqQyzzInfoDao.find(sql);
    }

    public List<YwRqRyzzFinalOtherEvidence> getFinalOtherEvidences(Long qyid) {
        String sql=" from " +YwRqRyzzFinalOtherEvidence.class.getName()+" where qyid='"+qyid+"'";
        return ywRqQyzzInfoDao.find(sql);
    }

    public List<YwRqRyzzOtherEvidence> getOtherEvidences(Long qyid,String acceptNo) {
        String sql=" from " +YwRqRyzzOtherEvidence.class.getName()+" where qyid='"+qyid+"' and acceptNo='"+acceptNo+"'";
        return ywRqQyzzInfoDao.find(sql);
    }

    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#importFinalData(com.augurit.gzcgwsp.qyzz.web.form.YwRqQyzzInfoForm)
     */
    public Map importFinalData(YwRqQyzzInfoForm form) {
        Long qyId=form.getQyid();
        YwComFinalQyxx qyxx=this.ywComQyxxFinalService.getEntityByQyId(qyId);
        if(qyxx==null){
            qyxx=new YwComFinalQyxx();
        }
        qyxx=this.buildQyxx(form, qyxx);
        this.ywComQyxxFinalService.saveOrUpdateEntity(qyxx);
        return null;
    }

    private YwComFinalQyxx buildQyxx(YwRqQyzzInfoForm form,YwComFinalQyxx qyxx){
        qyxx.setQyid(form.getQyid());
        qyxx.setSqdw(form.getSqdw());
        qyxx.setFddbr(form.getFddbr());
        qyxx.setAddress(form.getAddress());
        qyxx.setPost(form.getPost());
        qyxx.setEmail(form.getEmail());
        qyxx.setYwlxr(form.getYwlxr());
        qyxx.setYwlxrtel(form.getYwlxrtel());
        qyxx.setGszcdjh(form.getGszcdjh());
        qyxx.setZczj(form.getZczj());
        qyxx.setCsmj(form.getCsmj());
        qyxx.setRsJsry(form.getRsJsry());
        qyxx.setRsWxg(form.getRsWxg());
        qyxx.setRsTotal(form.getRsTotal());
        qyxx.setDwslGyrq(form.getDwslGyrq());
        qyxx.setDwslJyrq(form.getDwslJyrq());
        qyxx.setQyjs(form.getQyRemarks());
        return qyxx;
    }

 
    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#writeZsData(com.augurit.gzcgwsp.qyzz.web.form.YwRqQyzzInfoForm, java.lang.String)
     */
    public String writeZsData(YwRqQyzzInfoForm form,YwComQyxxForm qyxx, String context) {
        String inpath=context+"/Templates/rqjyxk/qyzz.xls";
        String tempOutPath="Templates/rqjyxk/outfile/qyzz/outfile";
        tempOutPath=this.buildPath(tempOutPath, "xls");
        String outfilepath=context+"/"+tempOutPath;
        outfilepath=outfilepath.replace("/", File.separator);
        String outdir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
        File file=new File(outdir);
        if(!file.exists()){
            file.mkdirs();
        }
  
        writerDataExcel(inpath,outfilepath,form,qyxx);
     	String dir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
		String filename=outfilepath.substring(outfilepath.lastIndexOf(File.separator)+1,outfilepath.length());
		try {//删除其他文件
			FileUtil.delDir(dir,filename);
		} catch (IOException e) {
			log.error("删除文件错误"+e);
		}
        return tempOutPath;
    }
    
    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#writeFbData(com.augurit.gzcgwsp.qyzz.web.form.YwRqQyzzInfoForm, com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm, java.lang.String)
     */
    public String writeFbData(YwRqQyzzInfoForm form, YwComQyxxForm qyxx,
            String context) {
        String inpath=context+"/Templates/rqjyxk/qyzzfb.xls";
        String tempOutPath="Templates/rqjyxk/outfile/qyzzfb/outfile";
        tempOutPath=this.buildPath(tempOutPath, "xls");
        String outfilepath=context+"/"+tempOutPath;
        outfilepath=outfilepath.replace("/", File.separator);
        String outdir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
        File file=new File(outdir);
        if(!file.exists()){
            file.mkdirs();
        }
  
        writerFbDataExcel(inpath,outfilepath,form,qyxx);
    	String dir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
		String filename=outfilepath.substring(outfilepath.lastIndexOf(File.separator)+1,outfilepath.length());
		try {//删除其他文件
			FileUtil.delDir(dir,filename);
		} catch (IOException e) {
			log.error("删除文件错误"+e);
		}
        return tempOutPath;
    }
    /**
     * 复制模版写入数据
     * @param inpath
     * @param outfilepath
     * @param form
     */
    private void writerFbDataExcel(String inpath, String outfilepath,
            YwRqQyzzInfoForm form,YwComQyxxForm qyxx) {
        WritableWorkbook wwb;
        try {
            wwb = ExcelUtil.createWorkbookByOld(inpath, outfilepath);
            WritableSheet wsOne = ExcelUtil.getWritableSheetByIndex(wwb, 0);
            copyFbData(wsOne,form,qyxx);
            wsOne.setProtected(true);
            wwb.write();
            wwb.close();
        } catch (Exception e) {
            log.error("写文件错误"+e);
        } 
    }

    
    /**
     * 复制模版写入数据
     * @param inpath
     * @param outfilepath
     * @param form
     */
    private void writerDataExcel(String inpath, String outfilepath,
            YwRqQyzzInfoForm form,YwComQyxxForm qyxx) {
        WritableWorkbook wwb;
        try {
            wwb = ExcelUtil.createWorkbookByOld(inpath, outfilepath);
            WritableSheet wsOne = ExcelUtil.getWritableSheetByIndex(wwb, 0);
            copyZsData(wsOne,form,qyxx);
            wsOne.setProtected(true);
            wwb.write();
            wwb.close();
        } catch (Exception e) {
            log.error("写文件错误"+e);
        } 
    }

    /**
     * 写数据
     * @param wsOne
     * @param form
     */
    private void copyZsData(WritableSheet wsOne, YwRqQyzzInfoForm form,YwComQyxxForm qyxx) {
       
        try {
            WritableCellFormat wcf=ExcelUtil.createCellFormat("宋体", 20, Alignment.LEFT, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf1=ExcelUtil.createCellFormat("宋体", 20, Alignment.LEFT, VerticalAlignment.CENTRE,true);
            WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 12, Alignment.LEFT, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf3=ExcelUtil.createCellFormat("宋体", 12, Alignment.RIGHT, VerticalAlignment.CENTRE,false);
            wcf.setLocked(true);
            wcf1.setLocked(true);
            wcf2.setLocked(true);
            wcf3.setLocked(true);
            ExcelUtil.modiStrCell2(wsOne, 4,14, qyxx.getZsbh()==null?"":qyxx.getZsbh(), wcf);//编号
            ExcelUtil.modiStrCell2(wsOne, 7, 2, form.getSqdw()==null?"":form.getSqdw(), wcf);//申请单位
            ExcelUtil.modiStrCell2(wsOne,7, 4, qyxx.getZzdj()==null?"":qyxx.getZzdj(), wcf1);//
            ExcelUtil.modiStrCell2(wsOne, 10, 16, "广州市城市管理委员会", wcf);//发证机关
            ExcelUtil.modiStrCell2(wsOne, 9, 19, qyxx.getYear()==null?"":qyxx.getYear(), wcf2);//开始时间
            ExcelUtil.modiStrCell2(wsOne, 11, 19, qyxx.getMonth()==null?"":qyxx.getMonth(),wcf3);//开始时间
            ExcelUtil.modiStrCell2(wsOne, 13, 19, qyxx.getDay()==null?"":qyxx.getDay(), wcf2);//发证日期
            
        } catch (Exception e) {
            e.printStackTrace();
            log.error("写入正式数据出现错误"+e);
        } 
        
    }

    
    /**
     * 写副本数据
     * @param wsOne
     * @param form
     */
    private void copyFbData(WritableSheet wsOne, YwRqQyzzInfoForm form,YwComQyxxForm qyxx) {
        try {
            WritableCellFormat wcf=ExcelUtil.createCellFormat("宋体", 14, Alignment.LEFT, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf1=ExcelUtil.createCellFormat("宋体", 14, Alignment.LEFT, VerticalAlignment.CENTRE,true);
            WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 14, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf3=ExcelUtil.createCellFormat("宋体", 14, Alignment.LEFT, VerticalAlignment.TOP,false);
            WritableCellFormat wcfdate=ExcelUtil.createCellFormat("宋体",12, Alignment.RIGHT, VerticalAlignment.CENTRE,false);
            wcf.setLocked(true);
            wcf1.setLocked(true);
            wcf2.setLocked(true);
            wcf3.setLocked(true);
            wcfdate.setLocked(true);
            wcf.setWrap(true);
            wcf1.setWrap(true);
            wcf2.setWrap(true);
            wcf3.setWrap(true);
            ExcelUtil.modiStrCell2(wsOne, 3, 4, form.getSqdw()==null?"":form.getSqdw(), wcf);//申请单位
            ExcelUtil.modiStrCell2(wsOne,3, 5, qyxx.getAddress()==null?"":qyxx.getAddress(), wcf1);//负责人
            ExcelUtil.modiStrCell2(wsOne,3, 7, qyxx.getClsj()==null?"":DateUtilsEX.dateFormate(qyxx.getClsj(), "yyyy年MM月dd日"), wcf);//成立时间
            ExcelUtil.modiStrCell2(wsOne,3, 8, qyxx.getZczj()==null?"":qyxx.getZczj(), wcf);//注册资本金
            ExcelUtil.modiStrCell2(wsOne,3, 9, qyxx.getGszcdjh()==null?"":qyxx.getGszcdjh(), wcf);//营业执照注册号
            ExcelUtil.modiStrCell2(wsOne,3, 10, qyxx.getJjlx()==null?"":qyxx.getJjlx(), wcf);//注册经济类型
            ExcelUtil.modiStrCell2(wsOne,3, 11, qyxx.getZzdj()==null?"":qyxx.getZzdj(), wcf);//主项目资质等级
            ExcelUtil.modiStrCell2(wsOne,3, 12, form.getFbzsbh()==null?"":form.getFbzsbh(), wcf);//证书编号
            ExcelUtil.modiStrCell2(wsOne,3, 13, qyxx.getFddbr()==null?"":qyxx.getFddbr(), wcf2);//法定代表人
            ExcelUtil.modiStrCell2(wsOne,5, 13, qyxx.getFddbrZw()==null?"":qyxx.getFddbrZw(), wcf2);//职务
            ExcelUtil.modiStrCell2(wsOne,7, 13, qyxx.getFddbrZc()==null?"":qyxx.getFddbrZc(), wcf2);//职称
            ExcelUtil.modiStrCell2(wsOne,3, 14, qyxx.getQyfzr()==null?"":qyxx.getQyfzr(), wcf2);//企业负责人
            ExcelUtil.modiStrCell2(wsOne,5, 14, qyxx.getQyfzrZw()==null?"":qyxx.getQyfzrZw(), wcf2);//职务
            ExcelUtil.modiStrCell2(wsOne,7, 14, qyxx.getQyfzrZc()==null?"":qyxx.getQyfzrZc(), wcf2);//职称
            ExcelUtil.modiStrCell2(wsOne,3, 15, qyxx.getJsfzr()==null?"":qyxx.getJsfzr(), wcf2);//技术负责人
            ExcelUtil.modiStrCell2(wsOne,5, 15, qyxx.getJsfzrZw()==null?"":qyxx.getJsfzrZw(), wcf2);//技术负责人
            ExcelUtil.modiStrCell2(wsOne,7, 15, qyxx.getJsfzrZc()==null?"":qyxx.getJsfzrZc(), wcf2);//技术负责人
            String remarks=form.getIeiRemarks();
            ExcelUtil.modiStrCell2(wsOne,2, 17, remarks==null?"":remarks, wcf3);//备注
            ExcelUtil.modiStrCell2(wsOne,9, 6, form.getCbgcfw()==null?"":form.getCbgcfw(), wcf3);//承包工程范围
            
            //ExcelUtil.modiStrCell2(wsOne, 10, 16,form.getSajg()==null?"广州市城市委员会":form.getSajg(), wcf);//发证机关
            ExcelUtil.modiStrCell2(wsOne, 12, 31, qyxx.getYear()==null?"":parseYear(qyxx.getYear()), wcfdate);//开始时间
            ExcelUtil.modiStrCell2(wsOne, 14, 31, qyxx.getMonth()==null?"":parseMonth(qyxx.getMonth()),wcfdate);//开始时间
            ExcelUtil.modiStrCell2(wsOne, 16, 31, qyxx.getDay()==null?"":parseDay(qyxx.getDay()), wcfdate);//发证日期
            
        } catch (Exception e) {
            e.printStackTrace();
            log.error("写入副本正式数据出现错误"+e);
        } 
        
    }

    /**
     * 生成后面的文件路径加上年月
     * @param realpath 定义的目录
     * @param fileNamesuffix 文件后缀名
     * @return
     */
    private String buildPath(String realpath,String fileNamesuffix){
        String fileName = GetFileName.getFileName(fileNamesuffix);
        String dateDir = GetFileName.getDirector();
        return realpath+"/"+dateDir+"/"+fileName;
        
    }

    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService#getInfos(java.lang.String)
     */
	public String[] getInfos(String acceptNo) {
		String[] infos=new String[4];
		String hql=" from "+YwRqRyzzEquipment.class.getName()+" where acceptNo='"+acceptNo+"'";
		String personhql=" from "+YwRqQyzzAzWxRyZs.class.getName()+" where acceptNo='"+acceptNo+"'";
		String techhql=" from "+YwRqQyzzJsRy.class.getName()+" where acceptNo='"+acceptNo+"'";
		List<YwRqRyzzEquipment> list=this.ywRqQyzzEquipmentDao.find(hql);
		List<YwRqQyzzAzWxRyZs> persons=this.ywRqQyzzAzWxRyZsDao.find(personhql);
		List<YwRqQyzzJsRy> techPesons=this.ywRqQyzzAzWxRyZsDao.find(techhql);
		
		if(list.size()>0){
			infos[0]="exist";
		}else{
			infos[0]="notexist";
		}
		if(persons.size()>0){
			infos[1]="exist";
		}else{
			infos[1]="notexist";
		}
		if(techPesons.size()>0){
			infos[2]="exist";
		}else{
			infos[2]="notexist";
		}
		return infos;
	}
	
    /**  
     * 把中文数字解析为阿拉伯数字(Integer)  
     * @param chineseNumber 中文数字  
     * @return 阿拉伯数字(Integer),如果是无法识别的中文数字则返回-1  
     */  
    public static String parseYear(String chineseNumber){  
    	if(chineseNumber.length()==4){
	    	char[] strs=chineseNumber.toCharArray(); 
	    	String onenum=String.valueOf(parseNumber(String.valueOf(strs[0])));
	    	String twonum=String.valueOf(parseNumber(String.valueOf(strs[1])));
	    	String threenum=String.valueOf(parseNumber(String.valueOf(strs[2])));
	    	String fornum=String.valueOf(parseNumber(String.valueOf(strs[3])));
	    	return onenum+twonum+threenum+fornum;
    	}else{
    		return chineseNumber;
    	}
    		
   } 
    
    public static String parseMonth(String month){   
    	char[] strs=month.toCharArray(); 
    	if(month.length()==1){
    		return "0"+String.valueOf(parseNumber(String.valueOf(strs[0])));
    	}else if(month.length()==2){
    		int monthstr=parseNumber(month);
    	    return String.valueOf(monthstr);
    	}
    	return "";
   }   
    public static String parseDay(String day){   
    	char[] strs=day.toCharArray(); 
    	if(day.length()==1){
    		return "0"+String.valueOf(parseNumber(String.valueOf(strs[0])));
    	}else if(day.length()==2){
    		int onenum=parseNumber(String.valueOf(strs[0]));
    		int twonum=parseNumber(String.valueOf(strs[1]));
    		int months=onenum+twonum;
    	    return String.valueOf(months);
    	}else if(day.length()==3){
    		int onenum=parseNumber(String.valueOf(strs[0])+String.valueOf(strs[1]));
    		int twonum=parseNumber(String.valueOf(strs[2]));
    		int months=onenum+twonum;
    	    return String.valueOf(months);
    	}
    	return null;
   }   

    public static int parseNumber(String chineseNumber){
    	int ret=0;
    	 if(chineseNumber.equals("一")){   
            ret=1;   
        }else if (chineseNumber.equals("二")){   
            ret=2;   
        }else if (chineseNumber.equals("三")){   
            ret=3;       
        }else if (chineseNumber.equals("四")){   
            ret=4;   
        }else if (chineseNumber.equals("五")){   
            ret=5;   
        }else if (chineseNumber.equals("六")){   
            ret=6;   
        }else if (chineseNumber.equals("七")){   
            ret=7;   
        }else if (chineseNumber.equals("八")){   
            ret=8;   
        }else if (chineseNumber.equals("九")){   
            ret=9;   
        }else if (chineseNumber.equals("〇") || chineseNumber.equals("零")){   
            ret=0;   
        }else if(chineseNumber.equals("十")) {   
        	 ret=10;   
        }else if(chineseNumber.equals("十一")) {   
        	 ret=11;   
        }else if(chineseNumber.equals("十二")) {   
        	 ret=12;   
        }else if(chineseNumber.equals("二十")) {   
        	 ret=20;   
        } else if(chineseNumber.equals("三十")) {   
        	 ret=30;   
        } 
    	 return ret;
    }
    
    
    
    public static void main(String[] args){   
        System.out.println(YwRqQyzzInfoServiceImpl.parseMonth("十二"));   
    }

	@Override
	public String wfBusYslTuih(YwRqQyzzInfoForm form, LoginUserForm loginUser)
			throws Exception {
    	String  loginUserName = loginUser.getUser().getUserName();
    	WfBusInstanceTaskForm taskForm = new WfBusInstanceTaskForm();
		taskForm.setHandleComments("资料不全，不予受理。");
		//把审批状态数据保存到ywWebserviceInfo ，交换给方欣
		ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getYwlxr(), form.getSjr(), form.getSqdw(), 
				form.getBusinessCode(), form.getApprovalNo(), loginUserName, loginUser.getOrg().getOrgName(), "ysl", new Date(), false, "预受理", taskForm);
//		System.out.println("form.getYslThyy() = "+java.net.URLDecoder.decode(form.getYslThyy(),"UTF-8"));
		this.changeYslState(form.getId(), 0L,taskForm.getHandleComments());
		
		//（网办）交换到市民网页
		Map map=exchangeStateService.buildMap(loginUser, null, form.getId().toString(), form.getTemplateCode(), false);
		String durationExpression = wfServiceEX.getDurationExpressionByTemplateCode(form.getTemplateCode());
		ywWebserviceForWbService.setValueAndSaveYwWebserviceForWb(loginUserName,form.getTemplateCode(),
				form.getId().toString(),durationExpression,"001",taskForm.getHandleComments(), map);
    	return null;
    }

	@Override
	public void updateAcceptNo(YwRqQyzzInfo entity) {
			String hql = "update YwRqQyzzInfo gd set gd.acceptNo='"+entity.getAcceptNo()+"' where gd.id=:id";
			Query query =ywRqQyzzInfoDao.getSession().createQuery(hql);
			query.setLong("id", entity.getId());
			query.executeUpdate();
	}
}
